package ntu.sna;

import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.collections15.Factory;

import edu.uci.ics.jung.algorithms.generators.random.BarabasiAlbertGenerator;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.UndirectedSparseGraph;

public class TestCode {
	public static void main(String[] args) {       
		Factory<Graph<MyNode, MyLink>> gFactory = new Factory<Graph<MyNode, MyLink>>(){
			public Graph<MyNode, MyLink> create(){
				return new UndirectedSparseGraph<MyNode, MyLink>();
			}
		};
		    
		Factory<MyNode> vFactory = new Factory<MyNode>(){
			public MyNode create(){
				return new MyNode();
			}
		};
		    
		Factory<MyLink> eFactory = new Factory<MyLink>(){
			public MyLink create(){
				return new MyLink(1.0 , 1.0);
			}
		}; 	
		
		Set<MyNode> set = new LinkedHashSet<MyNode>();
		BarabasiAlbertGenerator<MyNode , MyLink> generator1 = 
	        new BarabasiAlbertGenerator<MyNode , MyLink>(gFactory, vFactory, eFactory, 10000, 500 , set);
	       
		    generator1.evolveGraph(100);
		    Graph<MyNode , MyLink> g = generator1.create();
	        System.out.println(g);
	    	
	        int[] num_degree = new int[1000];
	        for(MyNode v : g.getVertices()){
	        	num_degree[g.degree(v)]++;
	        }
	        
	        for(int i = 0; i <1000 ;i++){
	        	System.out.println(num_degree[i]);
	        }
	        
	        AssortativityGenerator<MyNode , MyLink> generator2 =
				new AssortativityGenerator<MyNode , MyLink>(g , eFactory, 1);
	        generator2.run();
	        AssortativityCalculator<MyNode , MyLink> ac = 
	        	new AssortativityCalculator<MyNode , MyLink>(g);
	        double tmp = ac.run();
	        System.out.println("Assortativity:"+tmp);
	}
}